from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-26 14:06:41.536041
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 26, Feb, 2021
Time: 14:06:46
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.4306
Nobs: 214.000 HQIC: -47.2742
Log likelihood: 2476.67 FPE: 1.66316e-21
AIC: -47.8462 Det(Omega_mle): 1.10262e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.468376 0.136197 3.439 0.001
L1.Burgenland 0.072445 0.069816 1.038 0.299
L1.Kärnten -0.217272 0.059333 -3.662 0.000
L1.Niederösterreich 0.137640 0.159779 0.861 0.389
L1.Oberösterreich 0.251118 0.141921 1.769 0.077
L1.Salzburg 0.216237 0.075451 2.866 0.004
L1.Steiermark 0.098436 0.102052 0.965 0.335
L1.Tirol 0.129632 0.068052 1.905 0.057
L1.Vorarlberg -0.013954 0.061718 -0.226 0.821
L1.Wien -0.127493 0.133308 -0.956 0.339
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.474330 0.163766 2.896 0.004
L1.Burgenland 0.009168 0.083948 0.109 0.913
L1.Kärnten 0.352280 0.071343 4.938 0.000
L1.Niederösterreich 0.108216 0.192123 0.563 0.573
L1.Oberösterreich -0.127502 0.170649 -0.747 0.455
L1.Salzburg 0.198328 0.090724 2.186 0.029
L1.Steiermark 0.203734 0.122710 1.660 0.097
L1.Tirol 0.140702 0.081827 1.720 0.086
L1.Vorarlberg 0.156023 0.074211 2.102 0.036
L1.Wien -0.501961 0.160293 -3.132 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.314912 0.062307 5.054 0.000
L1.Burgenland 0.099898 0.031939 3.128 0.002
L1.Kärnten -0.018534 0.027144 -0.683 0.495
L1.Niederösterreich 0.095964 0.073096 1.313 0.189
L1.Oberösterreich 0.306080 0.064926 4.714 0.000
L1.Salzburg 0.001443 0.034517 0.042 0.967
L1.Steiermark -0.016952 0.046687 -0.363 0.717
L1.Tirol 0.078822 0.031132 2.532 0.011
L1.Vorarlberg 0.101079 0.028235 3.580 0.000
L1.Wien 0.044105 0.060986 0.723 0.470
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218875 0.068270 3.206 0.001
L1.Burgenland -0.004518 0.034996 -0.129 0.897
L1.Kärnten 0.019296 0.029741 0.649 0.516
L1.Niederösterreich 0.043941 0.080091 0.549 0.583
L1.Oberösterreich 0.386219 0.071139 5.429 0.000
L1.Salzburg 0.088219 0.037820 2.333 0.020
L1.Steiermark 0.178199 0.051154 3.484 0.000
L1.Tirol 0.040084 0.034112 1.175 0.240
L1.Vorarlberg 0.086717 0.030937 2.803 0.005
L1.Wien -0.057740 0.066822 -0.864 0.388
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.512836 0.135573 3.783 0.000
L1.Burgenland 0.060250 0.069496 0.867 0.386
L1.Kärnten 0.016303 0.059061 0.276 0.783
L1.Niederösterreich -0.013738 0.159048 -0.086 0.931
L1.Oberösterreich 0.133597 0.141271 0.946 0.344
L1.Salzburg 0.060834 0.075106 0.810 0.418
L1.Steiermark 0.123979 0.101585 1.220 0.222
L1.Tirol 0.210120 0.067740 3.102 0.002
L1.Vorarlberg 0.023628 0.061435 0.385 0.701
L1.Wien -0.118314 0.132698 -0.892 0.373
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191860 0.097495 1.968 0.049
L1.Burgenland -0.016185 0.049977 -0.324 0.746
L1.Kärnten -0.006494 0.042473 -0.153 0.878
L1.Niederösterreich 0.080027 0.114376 0.700 0.484
L1.Oberösterreich 0.406792 0.101592 4.004 0.000
L1.Salzburg -0.018303 0.054011 -0.339 0.735
L1.Steiermark -0.020772 0.073053 -0.284 0.776
L1.Tirol 0.181821 0.048714 3.732 0.000
L1.Vorarlberg 0.047613 0.044180 1.078 0.281
L1.Wien 0.160815 0.095427 1.685 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.248362 0.126042 1.970 0.049
L1.Burgenland 0.047940 0.064610 0.742 0.458
L1.Kärnten -0.037793 0.054909 -0.688 0.491
L1.Niederösterreich -0.034587 0.147866 -0.234 0.815
L1.Oberösterreich -0.068773 0.131339 -0.524 0.601
L1.Salzburg 0.056358 0.069825 0.807 0.420
L1.Steiermark 0.389441 0.094443 4.124 0.000
L1.Tirol 0.464825 0.062978 7.381 0.000
L1.Vorarlberg 0.158269 0.057116 2.771 0.006
L1.Wien -0.221567 0.123368 -1.796 0.072
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123603 0.151545 0.816 0.415
L1.Burgenland 0.021431 0.077683 0.276 0.783
L1.Kärnten -0.071240 0.066019 -1.079 0.281
L1.Niederösterreich 0.202270 0.177785 1.138 0.255
L1.Oberösterreich -0.014756 0.157914 -0.093 0.926
L1.Salzburg 0.254677 0.083953 3.034 0.002
L1.Steiermark 0.138609 0.113552 1.221 0.222
L1.Tirol 0.049720 0.075720 0.657 0.511
L1.Vorarlberg 0.065384 0.068673 0.952 0.341
L1.Wien 0.233865 0.148330 1.577 0.115
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.575131 0.081187 7.084 0.000
L1.Burgenland -0.036798 0.041617 -0.884 0.377
L1.Kärnten -0.014134 0.035368 -0.400 0.689
L1.Niederösterreich 0.000681 0.095245 0.007 0.994
L1.Oberösterreich 0.297386 0.084600 3.515 0.000
L1.Salzburg 0.018507 0.044977 0.411 0.681
L1.Steiermark 0.003655 0.060833 0.060 0.952
L1.Tirol 0.077040 0.040566 1.899 0.058
L1.Vorarlberg 0.118539 0.036790 3.222 0.001
L1.Wien -0.033009 0.079465 -0.415 0.678
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137007 0.046480 0.198397 0.249822 0.065123 0.126748 -0.037176 0.169907
Kärnten 0.137007 1.000000 0.003971 0.195340 0.165879 -0.122114 0.149759 0.009762 0.315800
Niederösterreich 0.046480 0.003971 1.000000 0.283725 0.077110 0.226815 0.153686 0.044852 0.368492
Oberösterreich 0.198397 0.195340 0.283725 1.000000 0.294578 0.280931 0.102328 0.069550 0.134692
Salzburg 0.249822 0.165879 0.077110 0.294578 1.000000 0.141751 0.054738 0.088300 -0.011158
Steiermark 0.065123 -0.122114 0.226815 0.280931 0.141751 1.000000 0.121613 0.113863 -0.103692
Tirol 0.126748 0.149759 0.153686 0.102328 0.054738 0.121613 1.000000 0.178663 0.165160
Vorarlberg -0.037176 0.009762 0.044852 0.069550 0.088300 0.113863 0.178663 1.000000 0.025024
Wien 0.169907 0.315800 0.368492 0.134692 -0.011158 -0.103692 0.165160 0.025024 1.000000